package com.itheima.article.controller;

import com.itheima.article.pojo.ApAuthor;
import com.itheima.article.service.ApAuthorService;
import com.itheima.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApiController {

    @Autowired
    private ApAuthorService apAuthorService;

    /**
     * 通过app端用户id查询作者信息
     * @param apUserId
     * @return
     */
    @GetMapping("/api/apAuthor/getByApUserIdWmUserId/{apUserId}/{wmUserId}")
    public ResultVo<ApAuthor> getByApUserIdWmUserId(@PathVariable(value = "apUserId") Long apUserId,
                                             @PathVariable(value = "wmUserId") Long wmUserId){
        ApAuthor apAuthor = apAuthorService.getByApUserIdWmUserId(apUserId,wmUserId);
        return ResultVo.ok(apAuthor);
    }

    /**
     * 远程调用添加作者账号
     * @param apAuthor
     * @return
     */
    @PostMapping("/api/apAuthor/add")
    public ResultVo add(@RequestBody ApAuthor apAuthor){
        if (apAuthorService.save(apAuthor)) {
            return ResultVo.ok();
        }
        return ResultVo.error();
    }
}
